package com.kata.chapter6;

import java.io.UnsupportedEncodingException;

/**
 * Created by Solidsnake on 2014/11/20.
 */
public class PBFFileReader implements IFileReader {

    private byte[] context = null;

    @Override
    public boolean hasBefore() {
        return true;
    }

    @Override
    public boolean hasAfter() {
        return true;
    }

    @Override
    public void before() {
        System.out.println("注入GOOGLE ProtoBuf 库....");
    }

    @Override
    public void after() {
        try {
            this.context = "这是正常PBF文档内容!!".getBytes("UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        System.out.println("反转PBF文档序列");
    }

    @Override
    public byte[] read() {
        try {
            this.context = "这是未反序列PBF文档内容!!".getBytes("UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return  this.context;
    }

    @Override
    public byte[] getContext() {
        return this.context;
    }
}
